import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { Result } from 'antd-mobile';
import axios from 'axios';
import BaseInfo from './components/BaseInfo';
// import { useOrganization } from '@/services/org';
import DescInfo from './components/DescInfo';
import Hr from '../../components/Hr';
import RecommendProducts from './components/RecommendProducts';

/**
 * 门店基本信息组件
 * @constructor
 */
const OrgInfo = () => {
  const { id } = useParams();

  const [data, setdata] = useState(null);
  const [front, setfront]:any = useState(null);
  const [room, setroom]:any = useState(null);
  useEffect(() => {
    getlist();
  }, []);
  const getlist = async () => {
    const { data } = await axios.get(
      `http://localhost:3000/organizationDetaile?id=${id}`,
    );
    data.data.data.forEach((item: React.SetStateAction<null>) => {
      setdata(item);
    });
    setfront(data.data.front);
    setroom(data.data.room);
  };

  if (!data) {
    return <Result title="提示" description="没有该门店信息" />;
  }
  return (
    <div>
      <BaseInfo data={data} room={room} />
      <Hr />
      <DescInfo data={data} front={front} />
      <Hr />
      <RecommendProducts />
    </div>
  );
};

export default OrgInfo;
